const WebSocketServer = require('ws').Server;
const express = require('express');
const app = express();
// 创建websocket服务器
const wss = new WebSocketServer({ port: 8888 });
// 注册连接开启事件，同时其他事件的初始化
wss.on('connection', function (ws) {
    console.log('ws client connected');
//接收客户端发送的报文事件
    ws.on('message', function (data) {
        ws.send('from ws:8888');
    });
    // 注册连接关闭事件
    ws.on('close', function (message) {
        //code
    });
});
console.log('websocket server running at ws://127.0.0.1:8888/');
